﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JavaScript8000
{
    using JavaScript8000.Parser;

    public partial class BrainFuck : Form
    {
        public BrainFuck()
        {
            InitializeComponent();
            TreeNode node = new TreeNode("Program");
            List<string> rule = Grammar.GetRule("Program");
            foreach (string s in rule)
            {
                node.Nodes.Add(s);
            }
            this.treeView1.Nodes.Add(node);
        }

        private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            foreach (TreeNode node in e.Node.Nodes)
            {
                if (node.Nodes.Count == 0)
                {
                    if (node.Text.StartsWith("<") || node.Text.StartsWith("\"") || "[]{}()|".Contains(node.Text))
                    {
                        continue;
                    }

                    List<string> rule = Grammar.GetRule(node.Text);

                    foreach (string s in rule)
                    {
                        node.Nodes.Add(s);
                    }
                }
            }
        }
    }
}
